package com.miaoquan.mqportal.controller;

import com.miaoquan.mqapitbk.domain.request.TklCreateRequest;
import com.miaoquan.mqcommon.api.CommonPage;
import com.miaoquan.mqcommon.api.CommonResult;
import com.miaoquan.mqmbg.model.TbkProduct;
import com.miaoquan.mqportal.domain.TbkProductItem;
import com.miaoquan.mqportal.feign.TklFeign;
import com.miaoquan.mqportal.service.TbkProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 淘宝客商品controller
 *
 * @author Fa
 * @date 2020-03-29 18:14
 */
@RestController
@RequestMapping("/tbkProduct")
public class TbkProductController {

    @Autowired
    private TbkProductService tbkProductService;

    @Autowired
    private TklFeign tklFeign;

    /**
     * 分页获取物料精选商品列表
     */
    @GetMapping("/getList")
    public CommonResult<CommonPage<TbkProduct>> getList(
            @RequestParam(defaultValue = "1") Integer pageNum, @RequestParam(defaultValue = "20") Integer pageSize) {
        List<TbkProduct> tbkProductList = tbkProductService.getList(pageNum, pageSize);
        return CommonResult.success(CommonPage.restPage(tbkProductList));
    }

    /**
     * 查询详情
     */
    @GetMapping("/getItem/{itemId}")
    public CommonResult<TbkProductItem> getItem(@PathVariable Long itemId) {
        TbkProductItem tbkProductItem = tbkProductService.getItem(itemId);
        return CommonResult.success(tbkProductItem);
    }

    /**
     * 创建淘口令
     */
    @PostMapping("/create/tkl")
    public CommonResult<String> createTkl(
//            @RequestParam(name = "userId", required = false) String userId,
//                                          @RequestParam(name = "text") String text,
//                                          @RequestParam(name = "url") String url,
//                                          @RequestParam(name = "logo", required = false) String logo
            @RequestBody TklCreateRequest tklCreateRequest
    ) {
        return tklFeign.createTkl(tklCreateRequest);
    }

}
